package sz.szsmk.citizencard.dialog;

import android.app.DialogFragment;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import sz.szsmk.citizencard.R;

/**
 * 展示电子市民卡折扣对话框
 */
public class PasswordDialog extends DialogFragment implements View.OnClickListener {

    private View actionLayout;

    private TextView elec_card_action_txt;

    private int action = 0;

    private String title = "";
    private String contentText = "";
    private String mOkText = "";
    private String mCancelText = "";
    private TextView content;
    private TextView textBtn1;
    private TextView textBtn2;
    private OnOkClickListener mOnOkClickListener;
    private OnCancelClickListener mOnCancelClickListener;

    public PasswordDialog() {
    }

    public interface OnOkClickListener {
        void onOkClick();
    }

    public interface OnCancelClickListener {
        void onCancelClick();
    }


    public void setOnOkClickListener(OnOkClickListener onOkClickListener) {
        this.mOnOkClickListener = onOkClickListener;
    }

    public void setOnCancelClickListener(OnCancelClickListener onOkClickListener) {
        this.mOnCancelClickListener = onOkClickListener;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        getDialog().setCanceledOnTouchOutside(false);
        View view = inflater.inflate(R.layout.password_dialog, container);
        content = (TextView) view.findViewById(R.id.txt_1);
        elec_card_action_txt = (TextView) view.findViewById(R.id.elec_card_action_txt);
        actionLayout = view.findViewById(R.id.action_layout);
        textBtn1 = (TextView) view.findViewById(R.id.password_cancel);
        textBtn2 = (TextView) view.findViewById(R.id.password_ok);
        textBtn1.setOnClickListener(this);
        textBtn2.setOnClickListener(this);
        return view;
    }

    public void setAction(int action) {
        this.action = action;
    }

    public void setTitle(String title){
        this.title = title;
    }
    public void setContent (String content){
        contentText = content;
    }
    public void setOkText(String okText){
        mOkText = okText;
    }
    public void setCancelText(String cancelText){
        mCancelText = cancelText;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        elec_card_action_txt.setText(title);
        content.setText(contentText);
        textBtn1.setText(mCancelText);
        textBtn2.setText(mOkText);

    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.password_cancel) {
            dismiss();
            if (null != mOnCancelClickListener) {
                mOnCancelClickListener.onCancelClick();
            }
        } else if (id == R.id.password_ok) {
            dismiss();

            if (null != mOnOkClickListener) {
                mOnOkClickListener.onOkClick();
            }
        }
    }
}
